import math

def Csum(num1, num2):
    return num1 + num2

def Cdel(num1, num2):
    return num1 - num2

def Cmul(num1, num2):
    return num1 * num2

def Chu(num1, num2):
    if num2 == 0:
        print("除数不为0")
        return None
    return num1 / num2

def Cpow(num1, num2):
    return num1 ** num2

def Clog(num1, num2):
    try:
        if isinstance(num1, complex) or isinstance(num2, complex):
            import cmath
            return cmath.log(num1, num2)
        else:
            return math.log(num1, num2)
    except ValueError:
        print("对数运算输入值不合法，请确保底数大于0且不等于1，真数大于0。")
        return None
    except ZeroDivisionError:
        print("对数运算中底数不能为1。")
        return None

flag = True
while flag:
    choice_type = input("请问：需要复数（1）还是整数（2）运算：")
    if choice_type == "1":
        try:
            num1 = complex(input("请输入一个数（支持如 3+4j 格式）："))
            num2 = complex(input("请输入另一个数（支持如 3+4j 格式）："))
        except ValueError:
            print("输入的复数格式有误，请重新输入，例如 3+4j。")
            continue
    elif choice_type == "2":
        try:
            num1 = int(input("请输入一个数："))
            num2 = int(input("请输入另一个数："))
        except ValueError:
            print("输入的不是有效的整数，请重新输入。")
            continue
    else:
        print("输入无效，请输入 1 或 2。")
        continue

    operator = input("请输入运算符(+-*/^log)：")

    if operator == "+":
        print(num1, operator, num2, "=", Csum(num1, num2))
    elif operator == "-":
        print(num1, operator, num2, "=", Cdel(num1, num2))
    elif operator == "*":
        print(num1, operator, num2, "=", Cmul(num1, num2))
    elif operator == "/":
        result = Chu(num1, num2)
        if result is not None:
            print(num1, operator, num2, "=", result)
    elif operator == "^":
        print(num1, operator, num2, "=", Cpow(num1, num2))
    elif operator == "log":
        result = Clog(num1, num2)
        if result is not None:
            print("log以", num2, "为底", num1, "的对数是:", result)

    if input("是否继续？Y/N：").upper() == "N":
        flag = False